<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
</head>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
        </div>
    </header>

    <script id="chkBillTemp" type="text/x-dot-template">

        {{~ it:value:index}}
        <li class="aui-list-item" onclick="goPage('{{= it[index].sysid }}','{{= it[index].code }}');">
            <div class="aui-media-list-item-inner">
                <div class="aui-list-item-inner ">
                    <div class="aui-list-item-text">
                        <div class="aui-list-item-title aui-font-size-14">
                            检测单号:{{= it[index].code }}
                        </div>
                    </div>
                    <div class="aui-list-item-text aui-font-size-12">
                        设备编码:{{= it[index].equipCode }}
                    </div>
                    <div class="aui-list-item-text aui-font-size-12">
                        检测模板:[{{= it[index].chkTemplateCode }}]{{= it[index].chkTemplateName }}
                    </div>
                    <div class="aui-list-item-text aui-font-size-12">
                        检测类型:{{= it[index].chkTypeName }}
                    </div>
                    <div class="aui-list-item-text aui-font-size-12">
                        计划日期:{{= it[index].billDate }}
                    </div>
                    <div class="aui-list-item-text aui-font-size-12">
                        审核状态:{{= it[index].processState }}
                    </div>
                    <div class="aui-list-item-text aui-font-size-12">
                        处理结果{{= it[index].chkResult }}
                    </div>
                </div>
            </div>
        </li>
        {{~}}

    </script>
    <div class="aui-content aui-margin-b-15" style="margin-top:50px;">
        <div class="aui-searchbar" id="search" style="position: relative;">
            <div class="aui-searchbar-input aui-border-radius">
                <i class="aui-iconfont aui-icon-search"></i>
                <div class="aui-searchbar-input">
                    <form action="javascript:doSearch();">
                        <input type="search" placeholder="请输入设备编码" id="equipCode" onclick="getIdSelector();">
                    </form>
                </div>
            </div>
            <div class="aui-btn aui-btn-primary" style="margin-right: 0.5rem;background-color: #03a9f4" onclick="doSearch()">搜索</div>
        </div>
    </div>

    <div class="aui-content aui-margin-b-15">
        <ul class="aui-list aui-media-list" id="chkBillList">

        </ul>
    </div>
    <footer class="aui-bar aui-bar-tab" id="footer">
        <div class="aui-bar-tab-item" tapmode id="scan" onclick="doScan()">
            <i class="aui-iconfont aui-icon-scan aui-text-epblue" style="font-size: 1.8rem"></i>
        </div>
    </footer>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/doT.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript">
    var chkBillType = "";
    var title = "";
    apiready = function() {
        title = api.pageParam.title;
        document.getElementById("title").innerHTML = title;
        doSearch();
    };

    // 获取光标所在组件的id
    function getIdSelector() {
        var e = event || window.event;
        var el = e.srcElement || e.target;
        $("#" + el.id).select();
    }

    //扫描
    function doScan() {
        var moduleScanner = api.require('moduleScanner');
        var params = {
            top: 150, //扫描窗口的上边距
            width: 250, //扫描窗口的宽
            height: 250, //扫描窗口的高
            useColor: false, //是否使用自己设定的颜色(startColor和endColor),
            //如果不使用设定的颜色就使用默认的那张网格图
            startColor: '#0F08C8FF', //渐变起始颜色
            endColor: '#7F08C8FF', //渐变结束颜色
            animTime: 2200, //扫描动画时间,单位为毫秒
        };
        moduleScanner.toScannerActivityForResult(params, function(ret, err) {

            $("#equipCode").val(ret);
            //查询仓库
            doSearch();
        });
    }

    //PDA自带扫描回车事件
    $("#equipCode").on('keypress', function(e) { //#keyword为input文本框
        var keycode = e.keyCode;
        var sm = $(this).val();
        if (keycode == '13') {
            $("#equipCode").val(sm);
            doSearch();
        }
    });

    //查询检测单
    function doSearch() {

        //检测单类型（1-材料检测单，2-在制品检测单，3-5S检测单，4-4W检测单，5-设备检测单）
        chkBillType = api.pageParam.chkBillType;
        //设备编码
        var equipCode = $("#equipCode").val();
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getChkBill";
        var data = {
            values: {
                chkBillType: chkBillType,
                equipCode: equipCode,
                un: un,
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function(ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                if (myobj.code == '0') {
                    var list = eval(myobj.list);

                    var evaluation = doT.template($api.dom('#chkBillTemp').innerHTML);
                    $api.dom('#chkBillList').innerHTML = evaluation(list);
                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }

    //去处理
    function goPage(sysid, code) {

        api.openWin({
            name: 'qcmChkBillDeal5s',
            url: 'qcmChkBillDeal5s.html',
            pageParam: {
                chkBillId: sysid,
                chkBillCode: code,
                name: "qcmChkBillEm",
                title: title + "处理",
            }
        });
    }

    //返回按钮
    function closeWin() {
        api.closeWin({});
    }
</script>

</html>
